package com.zxc.bootquartz;

import org.quartz.*;
import org.springframework.scheduling.quartz.QuartzJobBean;

import java.util.Date;

//持久化
@PersistJobDataAfterExecution
//禁止并发执行(Quartz不要并发地执行同一个job定义（这里指一个job类的多个实例）)
@DisallowConcurrentExecution
public class QuartzJob extends QuartzJobBean {
    @Override
    protected void executeInternal(JobExecutionContext context) {
        try {
            String schedulerInstanceId = context.getScheduler().getSchedulerInstanceId();
            System.out.println(schedulerInstanceId);
            System.out.println("任务名称：" + context.getJobDetail().getKey().getName());
            System.out.println("任务时间" + new Date());
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println();
    }
}
